﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PTTK_HTTT_06.BUS;
using System.Data;

namespace PTTK_HTTT_06.DAO
{
    class BO_PHAN_DB
    {
        #region public static List<BO_PHAN> LayDanhSach()
        public static List<BO_PHAN> LayDanhSach()
        {
            DataProvider dataProvider = new DataProvider();
            string sqlStr = "select * from BO_PHAN";
            if (!dataProvider.IsConnect())
                dataProvider.Connect();
            DataTable dt = dataProvider.ExcuteQueryDataTable(sqlStr);
            dataProvider.Disconnect();

            if (dt != null && dt.Rows.Count <= 0)
                return null;

            List<BO_PHAN> boPhanList = new List<BO_PHAN>();
            for (int i = 0, count = dt.Rows.Count; i < count; i++)
            {
                BO_PHAN bp = new BO_PHAN();
                bp.MaBoPhan = int.Parse(dt.Rows[i]["MaBoPhan"].ToString());
                bp.PhuCap = decimal.Parse(dt.Rows[i]["PhuCap"].ToString());
                bp.TenBoPhan = dt.Rows[i]["TenBoPhan"].ToString();
                bp.TinhTrangKhoa = ((dt.Rows[i]["TinhTrangKhoa"].ToString() == "True") ? true : false);
                bp.TruongBoPhan = int.Parse(dt.Rows[i]["TruongBoPhan"].ToString());

                boPhanList.Add(bp);
            }

            return boPhanList;
        }
        #endregion
    }
}
